export interface ConnectionState {
  nodeId?: string;
  ticket?: string;
  isConnected: boolean;
  connectedTerminals: TerminalSession[];
  activeProxies: WebShareProxyInfo[];
  peers: string[];
}

export interface TerminalSession {
  sessionId: string;
  name?: string;
  status: string;
  createdAt: number;
  lastActivity: number;
  size: TerminalSize;
}

export interface TerminalSize {
  rows: number;
  cols: number;
}

export interface WebShareProxyInfo {
  localPort: number;
  publicPort: number;
  nodeId: string;
  status: string;
  createdAt: number;
}

export interface ConnectionConfig {
  ticket: string;
  nickname?: string;
  auto_reconnect: boolean;
  secret_key?: string;
}

export type ClientMessage =
  | { type: 'connect'; config: ConnectionConfig }
  | { type: 'disconnect' }
  | { type: 'createTerminal'; sessionId: string; shellPath?: string; name?: string }
  | { type: 'sendTerminalInput'; sessionId: string; data: number[] }
  | { type: 'resizeTerminal'; sessionId: string; rows: number; cols: number }
  | { type: 'closeTerminal'; sessionId: string }
  | { type: 'renameTerminal'; sessionId: string; newName?: string }
  | { type: 'sendWebShare'; localPort: number; publicPort: number }
  | { type: 'sendWebUnshare'; publicPort: number };

export type ServerMessage =
  | { type: 'connected'; nodeId: string; ticket: string }
  | { type: 'disconnected' }
  | { type: 'terminalCreated'; sessionId: string }
  | { type: 'terminalOutput'; sessionId: string; data: number[] }
  | { type: 'terminalStatus'; sessionId: string; status: string }
  | { type: 'terminalStateChanged'; terminals: TerminalSession[] }
  | { type: 'nodeJoined'; nodeId: string }
  | { type: 'nodeLeft'; nodeId: string }
  | { type: 'webShareStarted'; localPort: number; publicPort: number }
  | { type: 'webShareStopped'; publicPort: number }
  | { type: 'error'; message: string };

export interface TerminalComponentProps {
  terminal: TerminalSession;
  onInput: (sessionId: string, data: number[]) => void;
  onResize: (sessionId: string, rows: number, cols: number) => void;
  onClose: (sessionId: string) => void;
  onRename: (sessionId: string, newName?: string) => void;
}